let TEMPLAETLIST = new Array();

$(function () {

    try {
        TEMPLAETLIST = [
            { key: "空白模板", value: getEmptyTemplate() },
            { key: "数据大屏", value: getDataTemplate() }
        ];
    }
    catch (e) {
        alert(e);
    }

});

//空白模板
let getEmptyTemplate = function () {
    let vTemplate = [];

    return vTemplate;
}

//数据大屏
let getDataTemplate = function () {
    let vTemplate = [
        { index: 0, x: 0, y: 0, width: 12, height: 2, model: initTitleModel(), echart: initTitle() },
        { index: 1, x: 0, y: 2, width: 3, height: 4, model: new xheModel(), echart: initRadar() },
        { index: 2, x: 0, y: 6, width: 3, height: 3, model: new xheModel(), echart: initLine() },
        { index: 3, x: 0, y: 9, width: 3, height: 3, model: new xheModel(), echart: initVBar() },
        { index: 4, x: 3, y: 2, width: 6, height: 7, model: new xheModel(), echart: initTable() },
        { index: 5, x: 3, y: 9, width: 2, height: 3, model: new xheModel(), echart: initPie() },
        { index: 6, x: 5, y: 9, width: 2, height: 3, model: new xheModel(), echart: initRosePie() },
        { index: 7, x: 7, y: 9, width: 2, height: 3, model: new xheModel(), echart: initRing() },
        { index: 8, x: 9, y: 2, width: 3, height: 3, model: new xheModel(), echart: initBarline() },
        { index: 9, x: 9, y: 5, width: 3, height: 3, model: new xheModel(), echart: initFunnel() },
        { index: 10, x: 9, y: 8, width: 3, height: 4, model: new xheModel(), echart: initGauge() }
    ];

    return vTemplate;
}

//初始化饼图
var initPie = function () {

    let _pie = new xheCharts();

    try {

        _pie.options.type = eCharts.type.Pie;
        _pie.options.titleText = "";
        _pie.options.titleSize = 18;
        _pie.options.tooltipShow = true;
        _pie.options.tooltipFormatter = "{b}:<br/>{c}条，占{d}%";
        _pie.options.center = [['50%', '50%']];
        _pie.options.data = [
            { name: '类型1', value: 200 },
            { name: '类型2', value: 100 },
            { name: '类型3', value: 300 },
            { name: '类型4', value: 250 }
        ];
    } catch (e) {
    }
    return _pie;
};

//初始化饼图
var initRosePie = function () {

    let _pie = new xheCharts();

    try {

        _pie.options.type = eCharts.type.Pie;
        _pie.options.titleText = "";
        _pie.options.titleSize = 18;
        _pie.options.tooltipShow = true;
        _pie.options.tooltipFormatter = "{b}:<br/>{c}条，占{d}%";
        _pie.options.roseType = true;
        _pie.options.radius = ['0%', '75%'];
        _pie.options.center = [['50%', '50%']];
        _pie.options.data = [
            { name: '类型1', value: 200 },
            { name: '类型2', value: 100 },
            { name: '类型3', value: 300 },
            { name: '类型4', value: 250 },
            { name: '类型5', value: 100 },
            { name: '类型6', value: 300 },
            { name: '类型7', value: 250 }
        ];
    } catch (e) {
    }
    return _pie;
};

//初始化柱图
var initVBar = function () {

    let _vBar = new xheCharts();
    try {

        _vBar.options.type = eCharts.type.VBar;
        _vBar.options.titleSize = 18;
        _vBar.options.toolboxShow = true;
        _vBar.options.top = '20%';
        _vBar.options.bottom = '4%';
        _vBar.options.left = '2%';
        _vBar.options.right = '5%';
        _vBar.options.axisYName = "单位:条";
        _vBar.options.tooltipShow = true;
        _vBar.options.tooltipFormatter = "{b}:<br/>{a}:{c}条";
        _vBar.options.legendGroup = new Array('指标1', '指标2', '指标3');
        //ECHARTSVBAR.colorList = new Array(['#4DC2FF', '#00CCFF', '#0099FF'], ['#F9B175', '#FF9966', '#FF9900'], ['#FFCCFF', '#FF99FF', '#FF66FF']);
        _vBar.options.data = [
            { key: "分类1", value: [30, 20, 25] },
            { key: "分类2", value: [40, 15, 25] },
            { key: "分类3", value: [60, 40, 30] },
            { key: "分类4", value: [35, 30, 40] }
        ];

    } catch (e) {
    }

    return _vBar;
};

//初始化柱图
var initHBar = function () {

    let _hBar = new xheCharts();

    try {
        _hBar.options.type = eCharts.type.HBar;
        _hBar.options.titleSize = 18;
        _hBar.options.top = '10%';
        _hBar.options.bottom = '4%';
        _hBar.options.left = '2%';
        _hBar.options.right = '15%';
        _hBar.options.axisYName = "单位:条";
        _hBar.options.tooltipShow = true;
        _hBar.options.tooltipFormatter = "{b}:{c}条";
        _hBar.options.legendGroup = new Array('分类1');
        //ECHARTSVBAR.colorList = new Array(['#4DC2FF', '#00CCFF', '#0099FF'], ['#F9B175', '#FF9966', '#FF9900'], ['#FFCCFF', '#FF99FF', '#FF66FF']);
        _hBar.options.data = [
            { key: "类型1", value: [30] },
            { key: "类型2", value: [40] },
            { key: "类型3", value: [60] },
            { key: "类型4", value: [35] }
        ];

    } catch (e) {
    }
    return _hBar;
};

//初始化折柱图
var initBarline = function () {

    let _barline = new xheCharts();

    try {
        _barline.options.type = eCharts.type.Barline;
        _barline.options.titleSize = 18;
        _barline.options.top = '20%';
        _barline.options.bottom = '4%';
        _barline.options.left = '2%';
        _barline.options.right = '4%';
        _barline.options.axisYName = "单位:条|单位:个";
        _barline.options.tooltipShow = true;
        _barline.options.tooltipFormatter = "{b}:{c}条";
        _barline.options.legendGroup = new Array('分类1', '分类2', '分类3');
        _barline.options.lineSmooth = false;
        _barline.options.data = [
            { key: "分类1", value: [30, 20, 25] },
            { key: "分类2", value: [40, 15, 25] },
            { key: "分类3", value: [60, 40, 30] },
            { key: "分类4", value: [35, 30, 40] },
            { key: "分类5", value: [30, 20, 25] },
            { key: "分类6", value: [40, 15, 25] },
            { key: "分类7", value: [60, 40, 30] },
            { key: "分类8", value: [35, 30, 40] }
        ];

    } catch (e) {
    }
    return _barline;
};

//初始化线图
var initLine = function () {

    let _line = new xheCharts();
    try {

        _line.options.type = eCharts.type.Line;
        _line.options.titleSize = 18;
        _line.options.toolboxShow = true;
        _line.options.top = '10%';
        _line.options.bottom = '4%';
        _line.options.left = '2%';
        _line.options.right = '5%';
        _line.options.parallel = true;
        _line.options.tooltipShow = true;
        _line.options.tooltipFormatter = "";
        _line.options.legendGroup = new Array('分类1', '分类2');
        _line.options.data = [
            { key: '类型1', value: [1321, 2014] },
            { key: '类型2', value: [1435, 2598] },
            { key: '类型3', value: [1376, 2456] },
            { key: '类型4', value: [976, 2100] },
            { key: '类型5', value: [942, 2231] },
            { key: '类型6', value: [832, 1113] },
            { key: '类型7', value: [931, 2011] }
        ];

    } catch (e) {
    }

    return _line;
};

//初始化地图
var initMap = function () {

    let _map = new xheCharts();

    try {
        _map.options.type = eCharts.type.Map;
        _map.options.tooltipShow = true;
        _map.options.tooltipFormatter = "{a}:</br>参保人员：{b}（万人）</br>参保单位：{c}（户）</br>技能补贴人员：{d}（人）";
        _map.options.top = '4%';
        _map.options.legendShow = true;
        _map.options.legendTop = '10%';
        _map.options.legendLeft = 'right';
        _map.options.labelShow = false;
        _map.options.labelColor = '4BF316';
        _map.options.labelWeight = 'normal';
        _map.options.labelSize = 12;
        _map.options.emphasisColor = "FFFFFF";
        _map.options.data = [
            { key: '东城区', value: [1, 1, 1] },
            { key: '西城区', value: [2, 2, 2] },
            { key: '朝阳区', value: [3, 3, 3] },
            { key: '海淀区', value: [4, 4, 4] },
            { key: '丰台区', value: [5, 5, 5] },
            { key: '大兴区', value: [6, 6, 6] },
            { key: '通州区', value: [7, 7, 7] },
            { key: '门头沟区', value: [8, 8, 8] },
            { key: '石景山区', value: [9, 9, 9] },
            { key: '顺义区', value: [10, 10, 10] },
            { key: '怀柔区', value: [11, 11, 11] },
            { key: '延庆区', value: [12, 12, 12] },
            { key: '密云区', value: [13, 13, 13] },
            { key: '平谷区', value: [14, 14, 14] },
            { key: '房山区', value: [15, 15, 15] },
            { key: '昌平区', value: [16, 16, 16] }
        ];
    }
    catch (e) { }

    return _map;
};

//初始化雷达图
var initRadar = function () {

    let _radar = new xheCharts();

    try {

        _radar.options.type = eCharts.type.Radar;
        _radar.options.tooltipShow = true;
        _radar.options.legendGroup = new Array('分类1', '分类2');
        _radar.options.center = [["50%", "50%"]];
        _radar.options.radius = ["70%"];
        _radar.options.areaOpacity = 0.4;
        _radar.options.data = [
            { key: "类型1", value: [80, 30] },
            { key: "类型2", value: [70, 90] },
            { key: "类型3", value: [35, 20] },
            { key: "类型4", value: [56, 90] },
            { key: "类型5", value: [40, 90] },
            { key: "类型6", value: [40, 120] }
        ];
    }
    catch (e) { }

    return _radar;
};

//初始化漏斗图
var initFunnel = function () {

    let _funnel = new xheCharts();

    try {
        _funnel.options.type = eCharts.type.Funnel;
        _funnel.options.left = "25%";
        _funnel.options.top = "4%";
        _funnel.options.bottom = "4%";
        _funnel.options.borderWidth = 0;
        _funnel.options.tooltipShow = true;
        _funnel.options.tooltipTrigger = "item";
        _funnel.options.tooltipFormatter = "{a} <br/>{b} : {c}%";
        _funnel.options.legendShow = false;
        _funnel.options.legendGroup = new Array('类型1', '类型2', '类型3', '类型4', '类型5', '类型6');
        _funnel.options.radius = ["50%"];
        _funnel.options.labelShow = true;
        _funnel.options.labelFormatter = '{c}%';
        _funnel.options.emphasisShow = true;
        _funnel.options.emphasisFormatter = '{b}实际: {c}%';
        _funnel.options.data = [
            { name: "类型1", value: 80 },
            { name: "类型2", value: 70 },
            { name: "类型3", value: 35 },
            { name: "类型4", value: 56 },
            { name: "类型5", value: 40 },
            { name: "类型6", value: 20 }
        ];
    }
    catch (e) {

    }
    return _funnel;
};

//初始化仪表盘
var initGauge = function () {

    let _gauge = new xheCharts();

    try {
        _gauge.options.type = eCharts.type.Gauge;

        _gauge.options.tooltipShow = true;
        _gauge.options.tooltipTrigger = "item";
        _gauge.options.tooltipFormatter = "{a} <br/>{b} : {c}%";
        _gauge.options.legendShow = false;
        _gauge.options.legendGroup = new Array('类型1');
        _gauge.options.radius = ["80%"];
        _gauge.options.center = [['50%', '60%']];
        _gauge.options.labelShow = true;
        _gauge.options.labelSize = 15;
        _gauge.options.labelLength = [10, 20];
        _gauge.options.labelPosition = "insideTop";
        _gauge.options.emphasisShow = true;
        _gauge.options.emphasisSize = 20;
        _gauge.options.emphasisWeight = "bold";
        _gauge.options.emphasisPosition = "insideBottom";
        _gauge.options.emphasisFormatter = "{value}%";
        _gauge.options.data = [
            { name: "类型1", value: 80 }
        ];
    }
    catch (e) {

    }
    return _gauge;
};

//初始化仪表盘
var initRing = function () {

    let _gauge = new xheCharts();

    try {
        _gauge.options.type = eCharts.type.Gauge;

        _gauge.options.tooltipShow = true;
        _gauge.options.tooltipTrigger = "item";
        _gauge.options.tooltipFormatter = "{a} <br/>{b} : {c}%";
        _gauge.options.legendShow = false;
        _gauge.options.legendGroup = new Array('类型1');
        _gauge.options.radius = ["70%"];
        _gauge.options.center = [['50%', '50%']];
        _gauge.options.labelShow = true;
        _gauge.options.labelSize = 15;
        _gauge.options.labelPosition = -10;
        _gauge.options.emphasisShow = true;
        _gauge.options.emphasisSize = 20;
        _gauge.options.containLabel = false;
        _gauge.options.containTick = false;
        _gauge.options.pointerShow = false;
        _gauge.options.section = [90, -270];

        _gauge.options.data = [
            { name: "类型1", value: 56 }
        ];
    }
    catch (e) {

    }
    return _gauge;
};

//初始化文字域
var initLabel = function () {

    let _label = new xheCharts();

    try {
        _label.options.type = eCharts.type.Label;
        _label.options.top = "3.8";
        _label.options.left = "2";
        _label.options.labelShow = true;
        _label.options.labelSize = 15;
        _label.options.labelColor = 'FFFFFF';
        _label.options.labelStyle = 'normal';
        _label.options.labelWeight = 'normal';
        _label.options.labelSize = '4';
        _label.options.labelFormatter = '标题:${name}';

        _label.options.data = [
            { name: "name", value: 56 }
        ];
    }
    catch (e) {

    }
    return _label;
};

var initLabelModel = function () {
    let _model = new xheModel();

    try {
        _model.options.titleShow = false;
        _model.options.borderShow = false;
    }
    catch (e) {

    }
    return _model;
}

//初始化文字域
var initTitle = function () {

    let _label = new xheCharts();

    try {
        _label.options.type = eCharts.type.Label;
        _label.options.top = "2.5";
        _label.options.left = "36.5";
        _label.options.labelShow = true;
        _label.options.labelSize = 5;
        _label.options.labelColor = '01ABFF';
        _label.options.labelStyle = 'normal';
        _label.options.labelWeight = 'normal';
        _label.options.labelFormatter = PROJECTNAME;
    }
    catch (e) {

    }
    return _label;
};

var initTitleModel = function () {
    let _model = new xheModel();

    try {
        _model.options.titleShow = false;
        _model.options.borderShow = false;
        _model.options.backgroudImage = "../../common/imgs/head2.png";
        _model.options.backgroudTransparent = 0;
    }
    catch (e) {

    }
    return _model;
}

//初始化交叉表
var initTable = function () {

    let _table = new xheCharts();
    try {
        vResult = [
            { "key": "东城区", "value": [{ "key": "男", "value": [12, 14] }, { "key": "女", "value": [14, 16] }] },
            { "key": "西城区", "value": [{ "key": "男", "value": [21, 23] }, { "key": "女", "value": [12, 35] }] },
            { "key": "朝阳区", "value": [{ "key": "男", "value": [21, 45] }, { "key": "女", "value": [32, 32] }] },
            { "key": "海淀区", "value": [{ "key": "男", "value": [11, 12] }, { "key": "女", "value": [14, 35] }] }
        ];
        // _table.options.legendGroup = ["指标1", "指标2"];
        // _table.options.quotaModel.category = "1";
        // _table.options.quotaModel.secondCategory = "1";
        // _table.options.type = eCharts.type.Table;
        // _table.options.data = vResult;

        // vResult = [
        //     { "key": "东城区", "value": [12, 14] },
        //     { "key": "西城区", "value": [21, 23] },
        //     { "key": "朝阳区", "value": [21, 45] },
        //     { "key": "海淀区", "value": [11, 12] }
        // ];
        _table.options.legendGroup = ["指标1", "指标2"];
        _table.options.labelFormatter = "行政区划|性别";
        _table.options.quotaModel.category = "1";
        _table.options.quotaModel.categoryText = "行政区划";
        _table.options.type = eCharts.type.Table;
        _table.options.data = vResult;

    }
    catch (e) {

    }
    return _table;
};

//初始化列表框
var initSelect = function () {

    let _select = new xheCharts();

    try {
        _select.options.type = eCharts.type.Select;
        _select.options.top = "3.8";
        _select.options.left = "2";
        _select.options.searchControl.text = '查询条件';

        _select.options.data = [
            { "key": "1", "value": "条件一", "defaulted": "true" },
            { "key": "2", "value": "条件二" },
            { "key": "3", "value": "条件三" },
            { "key": "4", "value": "条件四" },
            { "key": "5", "value": "条件五" }
        ];
    }
    catch (e) {

    }
    return _select;
};

//初始化列表框模块
var initSelectModel = function () {
    let _model = new xheModel();

    try {
        _model.options.titleShow = false;
        _model.options.borderShow = false;
        _model.options.backgroudImage = "";
        _model.options.backgroudTransparent = 0;
    }
    catch (e) {

    }
    return _model;
}

//初始化文本框
var initText = function () {

    let _text = new xheCharts();

    try {
        _text.options.type = eCharts.type.Text;
        _text.options.top = "3.8";
        _text.options.left = "2";
        _text.options.searchControl.text = '查询条件';
    }
    catch (e) {

    }
    return _text;
};

//初始化文本框模块
var initTextModel = function () {
    let _model = new xheModel();

    try {
        _model.options.titleShow = false;
        _model.options.borderShow = false;
        _model.options.backgroudImage = "";
        _model.options.backgroudTransparent = 0;
    }
    catch (e) {

    }
    return _model;
}

//初始化按钮
var initButton = function () {

    let _button = new xheCharts();

    try {
        _button.options.type = eCharts.type.Button;
        _button.options.top = "3.8";
        _button.options.left = "2";
        _button.options.searchControl.text = '查询';
    }
    catch (e) {

    }
    return _button;
};

//初始化按钮
var initExport = function () {

    let _button = new xheCharts();

    try {
        _button.options.type = eCharts.type.Export;
        _button.options.top = "3.8";
        _button.options.left = "2";
        _button.options.searchControl.text = '导出数据';
    }
    catch (e) {

    }
    return _button;
};

//初始化按钮模块
var initButtonModel = function () {
    let _model = new xheModel();

    try {
        _model.options.titleShow = false;
        _model.options.borderShow = false;
        _model.options.backgroudImage = "";
        _model.options.backgroudTransparent = 0;
    }
    catch (e) {

    }
    return _model;
}

//初始化按钮
var initDateControl = function () {

    let _date = new xheCharts();

    try {
        _date.options.type = eCharts.type.Date;
        _date.options.top = "3.8";
        _date.options.left = "2";
        _date.options.searchControl.text = '日期';
        _date.options.searchControl.format = "yyyy-MM-dd";
    }
    catch (e) {

    }
    return _date;
};

//初始化按钮模块
var initDateModel = function () {
    let _model = new xheModel();

    try {
        _model.options.titleShow = false;
        _model.options.borderShow = false;
        _model.options.backgroudImage = "";
        _model.options.backgroudTransparent = 0;
    }
    catch (e) {

    }
    return _model;
}